#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {
    vector<vector<int>> pre(n);
    vector<int> f(n);
    for (int i = 1; i < n; i++)
    {
        pre[i].push_back(i - 1);
        f[i] = i;
    }

    vector<int> res;
    for (auto& p : queries)
    {
        pre[p[1]].push_back(p[0]);
        for (int v = p[1]; v < n; v++)
            for (auto u : pre[v])
                f[v] = min(f[v], f[u] + 1);
        res.push_back(f[n - 1]);
    }
    return res;
}